package com.first.nell.statement

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.WebResourceRequest
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.lifecycle.ViewModel
import com.first.nell.ProjectConfig
import com.first.nell.base.BaseFragment
import com.first.nell.databinding.FragmentFirstNellStatementBinding
import com.first.nell.utils.UsageCountryUtil


class StatementLoanRejectFragment : BaseFragment() {

    private lateinit var mFirstNellFragmentFirstNellBinding: FragmentFirstNellStatementBinding

    override fun onFirstNellBindingFirstNellViewFirstNellModel(): List<ViewModel>? {
        val list = mutableListOf<ViewModel>()
        return list
    }


    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?,
    ): View {
        mFirstNellFragmentFirstNellBinding =
            FragmentFirstNellStatementBinding.inflate(inflater, container, false)
        return mFirstNellFragmentFirstNellBinding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        try {
            initFirstNellWebFirstNellViewFirstNellSettings()
            mFirstNellFragmentFirstNellBinding.wvStatement.loadUrl(ProjectConfig.NARSCASH_Privacy_Policy_Link)

        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    @SuppressLint("SetJavaScriptEnabled")
    private fun initFirstNellWebFirstNellViewFirstNellSettings() {
        mFirstNellFragmentFirstNellBinding.wvStatement.setInitialScale(100)
        mFirstNellFragmentFirstNellBinding.wvStatement.webViewClient = mFirstNellWebFirstNellClient
        val webSettings = mFirstNellFragmentFirstNellBinding.wvStatement.settings
        webSettings.javaScriptEnabled = true
        webSettings.setSupportZoom(true)
        webSettings.textZoom = 100
        webSettings.domStorageEnabled = true
        webSettings.builtInZoomControls = true
        webSettings.useWideViewPort = true
        webSettings.loadWithOverviewMode = true
        webSettings.cacheMode = WebSettings.LOAD_NO_CACHE
        webSettings.layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN
        try {
            webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW)
            webSettings.allowUniversalAccessFromFileURLs = true
            webSettings.allowFileAccessFromFileURLs = true
            webSettings.allowContentAccess = true
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    private val mFirstNellWebFirstNellClient = object : WebViewClient() {
        override fun shouldOverrideUrlLoading(
            view: WebView?,
            request: WebResourceRequest?,
        ): Boolean {
            return shouldOverrideUrlLoading(view, request!!.url.toString())
        }

        override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
            return false
        }
    }
}